clear
cd "YOURPATH" // Change this path accordingly, to this "Replication"-folder. Then simply run this file

clear matrix
clear mata
set matsize 11000
set maxvar 32000
set max_memory 1600g

// load data
use IEA_panel.dta

// Data Source is the TIPEA data on trade provisions in environmental agreements, https://www.chaire-epi.ulaval.ca/en/data/design-ieas. The data is expanded to a panel and furthermore includes data on amendments, sourced from Laurens, Hollway & Morin (2023) "Checking for Updates: Ratification, Design, and Institutional Adaptation", International Studies Quarterly 67(3), and additional information on protocol amendments based on the lineage in https://www.iea.ulaval.ca/en/agreements. Source for country-year data are the World Bank World Development Indicators, Yale EPI, Polity2 Project, as referenced in the paper.

// Do-file was run with STATA 18.

****************************************************

//gen variables
foreach var of varlist tot_GDP {
gen ln_`var' = ln(`var'+1)
}
gen region_order = 2
replace region_order = 1 if regional==1
replace region_order = 3 if multiregional==1
gen pluriregional =0
replace pluriregional=1 if region_order==2
gen pluriregional_ori=0
replace pluriregional_ori=1 if regions_ori<5 & regions_ori>1
gen region_order_ori = 2
replace region_order_ori = 1 if regional_ori==1
replace region_order_ori = 3 if multiregional_ori==1


// gen sample
gen sample=0
replace sample=1 if amendments!=. & accessions!=. & abs_norms!=. & age!=. & members!=. & bilateral!=1 & agreement_year>1945 & X100203!=1 & original_members>2


// Summary Statistics
sum accessions amendments abs_norms res_norms lib_norms RR LL d_econres av_GDPpc tot_GDP US_part regional multiregional if sample==1

// standardize control variables
foreach var of varlist d_econres av_GDPpc av_ln_GDPpc tot_GDP ln_tot_GDP av_EPI av_polity2 av_polconv av_MerchTrade pta_pair_share {
	egen std_`var' = std(`var') if sample==1
}

save iea_panel_estimationfile.dta, replace




*************************************  On IEA Level  *********************************+

bysort ID: egen acc_total=sum(accessions)
bysort ID: egen am_total=sum(amendments)

// REDUCE TO IEA-LEVEL PANEL
duplicates drop ID, force

keep if agreement_year>1945
drop if ID==4537 
keep if agreement_year<2018

drop std_d_econres std_av_ln_GDPpc_ori std_av_EPI_ori std_av_polity2_ori std_av_polconv_ori std_av_MerchTrade_ori std_pta_pair_share_ori

// standardize control variables
foreach var of varlist d_econres duration av_ln_GDPpc_ori av_EPI_ori av_polity2_ori av_polconv_ori av_MerchTrade_ori pta_pair_share_ori {
	egen std_`var' = std(`var') if sample==1
}

// Gen additional variables

gen om_squared = original_members^2
gen duration_sq=duration^2
gen duration_cub=duration^3

//funding mechanisms
egen funding = rowmax(X120501Establishmentofanewfundin X120502Referencestoanexistingfun)
//assistance
egen assistance = rowmax(X1101Technicalassistancetraining X1102Technologytransfer X1103Financialassistance X1104Emergencyassistanceincaseof)
//possibility to amend
egen amendposs = rowmax(X907Possibilitytoamendtheagreeme X910Possibilitytoamendtheannexes)
//possibility to access
egen accessposs = rowmax(X100202ExplicitlyopenRestricted X100201ExplicitlyopenUniversal)
//differential treatment for DCs
gen difftreat = X311Commonbutdifferentiatedrespo
//compliance, enforcment
egen compliance_enforcement = rowtotal(X1305Suspensionorrevocationofben X1306Suspensionoftheagreementorr)


//Generate dummies for subjects
gen Pollution = 0
replace Pollution = 1 if Subject=="Pollution"
gen Fish = 0
replace Fish = 1 if Subject=="Fish"
gen Freshwater = 0
replace Freshwater = 1 if Subject=="Freshwater"
gen Ocean = 0
replace Ocean = 1 if Subject=="Habitat and ocean"
gen Biodiversity = 0
replace Biodiversity = 1 if Subject=="Conservation of species and biodiversity"
gen Agriculture = 0
replace Agriculture = 1 if Subject=="Agriculture"
gen General = 0
replace General = 1 if Subject=="General environmental cooperation"
gen Energy = 0
replace Energy = 1 if Subject=="Energy"
gen Weapons = 0
replace Weapons = 1 if Subject=="Weapons and environment"
gen Others = 0
replace Others = 1 if Subject=="Others"

//interaction variables
gen regional_RR = regional_ori*RR
gen regional_LL = regional_ori*LL
gen pluriregional_RR = pluriregional_ori*RR
gen pluriregional_LL = pluriregional_ori*LL
gen multiregional_RR = multiregional_ori*RR
gen multiregional_LL = multiregional_ori*LL
gen compliance_enforcement_RR = compliance_enforcement*RR
gen compliance_enforcement_LL = compliance_enforcement*LL

//Summary Stats
sum acc_total am_total abs_norms res_norms lib_norms RR LL d_econres duration av_ln_GDPpc_ori ln_tot_GDP_ori av_EPI_ori av_polity2_ori av_MerchTrade_ori EU_part_ori US_part_ori funding assistance difftreat original_members amendposs compliance_enforcement pta_pair_share_ori if sample==1

order ID agreement_year Name acc_total am_total RR LL Subject

save iea_cross-section_estimationfile.dta, replace

////////////////////////////////////////////////  Estimations   ////////////////////////////////////////

//////////////////// Baseline

eststo clear

*amendments
eststo: ppml am_total abs_norms std_d_econres std_duration if sample==1
eststo: ppml am_total res_norms lib_norms std_d_econres std_duration if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration if sample==1

esttab using "Results\amendments_baseline.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear

*accessions
eststo: ppml acc_total abs_norms std_d_econres std_duration if sample==1
eststo: ppml acc_total res_norms lib_norms std_d_econres std_duration if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration if sample==1

esttab using "Results\accessions_baseline.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear



//////////// Controls

// Country Characteristics



* amendments
eststo: ppml am_total RR LL std_d_econres std_duration std_av_ln_GDPpc_ori if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration ln_tot_GDP_ori if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration av_EPI_ori if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration av_polity2_ori if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration av_MerchTrade_ori if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration std_av_ln_GDPpc_ori ln_tot_GDP_ori  av_EPI_ori av_polity2_ori av_MerchTrade_ori if sample==1

esttab using "Results\amendments_controls_country.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear




*accessions
eststo: ppml acc_total RR LL std_d_econres std_duration std_av_ln_GDPpc_ori if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration ln_tot_GDP_ori if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration av_EPI_ori if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration av_polity2_ori if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration av_MerchTrade_ori if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration std_av_ln_GDPpc_ori ln_tot_GDP_ori av_EPI_ori av_polity2_ori av_MerchTrade_ori if sample==1

esttab using "Results\accessions_controls_country.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear


// IEA Characteristics

*Subject Area
eststo: ppml am_total RR LL std_d_econres std_duration Pollution Fish Freshwater Ocean Biodiversity Agriculture General Energy Weapons Others if sample==1, nocon keep
eststo: ppml acc_total RR LL std_d_econres std_duration Pollution Fish Freshwater Ocean Biodiversity Agriculture General Energy Weapons Others if sample==1, nocon keep

esttab using "Results\amendments_accessions_subject.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear



*amendments
eststo: ppml am_total RR LL std_d_econres std_duration EU_part_ori if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration US_part_ori if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration funding if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration assistance if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration difftreat if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration if sample==1 & amendposs==1
eststo: ppml am_total RR LL std_d_econres std_duration EU_part_ori US_part_ori funding assistance difftreat if sample==1

esttab using "Results\amendments_controls_treaty.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear

*accessions
eststo: ppml acc_total RR LL std_d_econres std_duration EU_part_ori if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration US_part_ori if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration funding if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration assistance if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration difftreat if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration original_members om_squared if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration am_total if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration EU_part_ori US_part_ori funding assistance difftreat original_members om_squared am_total if sample==1

esttab using "Results\accessions_controls_treaty.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear



// Enforcement interactions
eststo: ppml am_total RR LL compliance_enforcement_RR compliance_enforcement_LL std_d_econres std_duration compliance_enforcement if sample==1
eststo: ppml acc_total RR LL compliance_enforcement_RR compliance_enforcement_LL std_d_econres std_duration compliance_enforcement if sample==1
esttab using "Results\enforcement.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear


///// Negative binomial

eststo: nbreg am_total abs_norms std_d_econres std_duration if sample==1
eststo: nbreg am_total res_norms lib_norms std_d_econres std_duration if sample==1
eststo: nbreg am_total RR LL std_d_econres std_duration if sample==1

esttab using "Results\nb_amendments.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear

eststo: nbreg acc_total abs_norms std_d_econres std_duration if sample==1
eststo: nbreg acc_total res_norms lib_norms std_d_econres std_duration if sample==1
eststo: nbreg acc_total RR LL std_d_econres std_duration if sample==1

esttab using "Results\nb_accessions.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear


//////  duration squared & cubic

eststo: ppml am_total RR LL std_d_econres std_duration duration_sq if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration duration_sq if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration duration_cub if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration duration_cub if sample==1
eststo: ppml am_total RR LL std_d_econres std_duration duration_sq duration_cub if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration duration_sq duration_cub if sample==1

esttab using "Results\dursq.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear


// Panel

use iea_panel_estimationfile.dta, clear

*** Set Panel
xtset ID year

// Amendments

eststo clear

eststo: ppmlhdfe amendments abs_norms std_d_econres if sample==1 , absorb(year) vce(cluster ID)
eststo: ppmlhdfe amendments res_norms lib_norms std_d_econres if sample==1 , absorb(year) vce(cluster ID)
eststo: ppmlhdfe amendments RR LL std_d_econres if sample==1, absorb(year) vce(cluster ID)

esttab using "Results\panel_amend.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear

// Accessions

eststo clear

eststo: ppmlhdfe accessions abs_norms std_d_econres if sample==1 , absorb(year) vce(cluster ID)
eststo: ppmlhdfe accessions res_norms lib_norms std_d_econres if sample==1 , absorb(year) vce(cluster ID)
eststo: ppmlhdfe accessions RR LL std_d_econres if sample==1, absorb(year) vce(cluster ID)

esttab using "Results\panel_access.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear

use iea_cross-section_estimationfile.dta, clear


//////  PTAs

eststo: ppml am_total RR LL std_d_econres std_duration pta_pair_share_ori if sample==1
eststo: ppml acc_total RR LL std_d_econres std_duration pta_pair_share_ori if sample==1

esttab using "Results\ptas.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear



/// Regional Agreements

* am_total
eststo: ppml am_total regional_RR pluriregional_RR multiregional_RR regional_LL pluriregional_LL multiregional_LL std_d_econres std_duration regional_ori pluriregional_ori multiregional_ori if sample==1, nocon

*acc_total
eststo: ppml acc_total regional_RR pluriregional_RR multiregional_RR regional_LL pluriregional_LL multiregional_LL std_d_econres std_duration regional_ori pluriregional_ori multiregional_ori if sample==1, nocon

esttab using "Results\regionality.csv", se(3) b(3) r2 replace drop() star(* 0.10 ** 0.05 *** 0.01) title()
eststo clear




